#ifndef _MySQLClient_H
#define _MySQLClient_H

#include <mysql/mysql.h>

#include <string>
#include <vector>
#include <memory>
using std::string;
using std::unique_ptr;
using std::vector;

class MySQLClient
{
public:
    static MySQLClient *getInstance()
    {
        if (!MySQLInstance)
        {
            MySQLInstance = unique_ptr<MySQLClient>(new MySQLClient());
        }
        return MySQLInstance.get();
    }
    bool connect(const string &host,
                 unsigned short port,
                 const string &user,
                 const string &passwd,
                 const string &db);
    bool writeOperationQuery(const string &sql);
    vector<vector<string>> readOperationQuery(const string &sql);

    static void dump(const vector<vector<string>> &res);

private:
    void init();

private:
    static unique_ptr<MySQLClient> MySQLInstance;
    MySQLClient();
    ~MySQLClient(); 
    MySQLClient(const MySQLClient &) = delete;
    MySQLClient &operator=(const MySQLClient &) = delete;

    MYSQL _conn;
};

#endif
